// Fill out your copyright notice in the Description page of Project Settings.
#include "SCustomList.h"

#include <iomanip>

#include "SlateOptMacros.h"
#include "Kismet/KismetMathLibrary.h"
#include "ListLibrary/GlobalConfig.h"
#include "ListLibrary/BaseWidget/SCollisionScrollBox_List.h"
#include "ListLibrary/BaseWidget/STextBlock_TextStyleLambda_List.h"
#include "Widgets/Colors/SColorBlock.h"
#include "Widgets/Images/SImage.h"
#include "Widgets/Input/SSlider.h"
#include "Widgets/Layout/SConstraintCanvas.h"
#include "Widgets/Layout/SSpacer.h"
#include "Widgets/Notifications/SNotificationList.h"
#include "Widgets/Notifications/SProgressBar.h"
#include "Widgets/Text/SMultiLineEditableText.h"

BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION


SCustomList::SCustomList()
	: MaxValue(100)
	  , MinValue(0)
	  , GrowValue(20)
	  , PillarNum(1)
	  , PillarBg(true)
	  , ShowZheLine(false)
	  , ShowYuan(false)
	  , TableWidth(420)
{
}

void SCustomList::Construct(const FArguments& InArgs)
{
	ChildSlot
	[
		SNew(SVerticalBox)

		+ SVerticalBox::Slot().AutoHeight()
		[
			SNew(SHorizontalBox)
			.Visibility_Lambda([this]()
			{
				if (ShowTitle)
					return EVisibility::Visible;
				else
					return EVisibility::Collapsed;
			})
			+ SHorizontalBox::Slot().AutoWidth()
			[
				SAssignNew(TitleText, STextBlock_TextStyleLambda_List)
				.Justification(ETextJustify::Left)
				.Text(FText::FromString(InArgs._Title))
				.TEXTSTYLE(InArgs._TitleStrStyle)
			]
			+ SHorizontalBox::Slot().FillWidth(1)
			[
				SNew(SSpacer)
			]
			+ SHorizontalBox::Slot().AutoWidth().VAlign(VAlign_Center)
			[
				SNew(SBox).WidthOverride(8).HeightOverride(8)
				[
					SNew(SImage)
					.SETIMAGE("ZhuZi_Blue")
				]
			]
			+ SHorizontalBox::Slot().AutoWidth().VAlign(VAlign_Center).Padding(FMargin(6, 0, 0, 0))
			[
				SAssignNew(OneInfo, STextBlock_TextStyleLambda_List)
				.Justification(ETextJustify::Left)
				.Text(FText::FromString(InArgs._ColorOneInfo))
				.TEXTSTYLE("AlibabaRegular_11_83AAD6FF")
			]
			+ SHorizontalBox::Slot().AutoWidth().VAlign(VAlign_Center).Padding(FMargin(16, 0, 0, 0))
			[
				SNew(SBox).WidthOverride(8).HeightOverride(8)
				          .Visibility_Lambda([this]()
				          {
					          if (PillarNum >= 2)
						          return EVisibility::Visible;
					          else
					          {
						          return EVisibility::Collapsed;
					          }
				          })
				[
					SNew(SImage)
					.SETIMAGE("ZhuZi_Green")
				]
			]
			+ SHorizontalBox::Slot().AutoWidth().VAlign(VAlign_Center).Padding(FMargin(6, 0, 0, 0))
			[
				SAssignNew(TwoInfo, STextBlock_TextStyleLambda_List)
				.Visibility_Lambda([this]()
				                                                    {
					                                                    if (PillarNum >= 2)
						                                                    return EVisibility::Visible;
					                                                    else
					                                                    {
						                                                    return EVisibility::Collapsed;
					                                                    }
				                                                    })
				.Justification(ETextJustify::Left)
				.Text(FText::FromString(InArgs._ColorTwoInfo))
				.TEXTSTYLE("AlibabaRegular_11_83AAD6FF")
			]
			+ SHorizontalBox::Slot().AutoWidth().VAlign(VAlign_Center).Padding(FMargin(16, 0, 0, 0))
			[
				SNew(SBox).WidthOverride(8).HeightOverride(8)
				          .Visibility_Lambda([this]()
				          {
					          if (PillarNum >= 3)
						          return EVisibility::Visible;
					          else
					          {
						          return EVisibility::Collapsed;
					          }
				          })
				[
					SNew(SImage)
					.SETIMAGE("ZhuZi_Yellow")
				]
			]
			+ SHorizontalBox::Slot().AutoWidth().VAlign(VAlign_Center).Padding(FMargin(6, 0, 0, 0))
			[
				SAssignNew(ThreeInfo, STextBlock_TextStyleLambda_List)
				.Visibility_Lambda([this]()
				                                                      {
					                                                      if (PillarNum >= 3)
						                                                      return EVisibility::Visible;
					                                                      else
					                                                      {
						                                                      return EVisibility::Collapsed;
					                                                      }
				                                                      })
				.Justification(ETextJustify::Left)
				.Text(FText::FromString(InArgs._ColorThreeInfo))
				.TEXTSTYLE("AlibabaRegular_11_83AAD6FF")
			]
			+ SHorizontalBox::Slot().AutoWidth().VAlign(VAlign_Center).Padding(FMargin(16, 0, 0, 0))
			[
				SNew(SBox).WidthOverride(8).HeightOverride(8)
				          .Visibility_Lambda([this]()
				          {
					          if (PillarNum >= 4)
						          return EVisibility::Visible;
					          else
					          {
						          return EVisibility::Collapsed;
					          }
				          })
				[
					SNew(SImage)
					.SETIMAGE("ZhuZi_White")
				]
			]
			+ SHorizontalBox::Slot().AutoWidth().VAlign(VAlign_Center).Padding(FMargin(6, 0, 0, 0))
			[
				SAssignNew(FourInfo, STextBlock_TextStyleLambda_List)
				.Visibility_Lambda([this]()
				                                                     {
					                                                     if (PillarNum >= 4)
						                                                     return EVisibility::Visible;
					                                                     else
					                                                     {
						                                                     return EVisibility::Collapsed;
					                                                     }
				                                                     })
				.Justification(ETextJustify::Left)
				.Text(FText::FromString(InArgs._ColorFourInfo))
				.TEXTSTYLE("AlibabaRegular_11_83AAD6FF")
			]
		]
		+ SVerticalBox::Slot().FillHeight(1).Padding(FMargin(0, 16, 0, 0))
		[
			SAssignNew(ListContent, SBox)
		]
	];
	UpDataList(TMap<FString, FCustomListInfo>());
}

END_SLATE_FUNCTION_BUILD_OPTIMIZATION


int32 SCustomList::OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGeometry, const FSlateRect& MyCullingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled) const
{
	SCompoundWidget::OnPaint(Args, AllottedGeometry, MyCullingRect, OutDrawElements, LayerId, InWidgetStyle, bParentEnabled);
	if (ShowZheLine && YuanImageS.Num() > 0)
	{
		FGeometry ZeroGeometry = YuanImageS[0]->GetCachedGeometry();
		//AbsolutePosition代表再父类中的位置
		if (!(ZeroGeometry.AbsolutePosition.X == 0 && ZeroGeometry.AbsolutePosition.Y == 0))
		{
			FGeometry OneListGeometry = GetCachedGeometry(); //获取自己再软件中的位置
			TArray<FVector2D> Points;
			for (int i = 0; i < YuanImageS.Num(); i++)
			{
				FGeometry TempGeometry = YuanImageS[i]->GetCachedGeometry(); //获取圆球再软件中的位置
				float X = (TempGeometry.AbsolutePosition.X - OneListGeometry.AbsolutePosition.X + 10) / AllottedGeometry.Scale;
				float Y = (TempGeometry.AbsolutePosition.Y - OneListGeometry.AbsolutePosition.Y + 10) / AllottedGeometry.Scale;
				FVector2D position = FVector2D(X, Y); //算出圆球在控件中的位置
				Points.Add(position);
			}
			FSlateDrawElement::MakeLines( //绘制线条
				OutDrawElements,
				LayerId++,
				AllottedGeometry.ToPaintGeometry(),
				Points, //线条坐标
				bParentEnabled ? ESlateDrawEffect::None : ESlateDrawEffect::DisabledEffect, //在原色基础之上在增加别的效果
				FColor::Yellow, //显得颜色
				true, //抗锯齿
				2 //线的宽度
			);
		}
	}
	return LayerId;
}

void SCustomList::UpDataList(TMap<FString, FCustomListInfo> InListData)
{
	ListData = InListData;



	int MaxNameLen = 0;
	for (auto& item : ListData)
	{
		if (item.Key.Len() > MaxNameLen)
			MaxNameLen = item.Key.Len();
	}
	
	//字体所占行数最多两行
	MaxNameLen = MaxNameLen / 2 + MaxNameLen % 2;
	//一个字体的宽度为14
	MaxNameLen *= 15;
	//创建这个表所需要的最小宽度
	int MinWidth = (MaxNameLen) * ListData.Num();
	//获取这个表的宽度
	if (GetCachedGeometry().Size.X != 0)
	{
		TableWidth = GetCachedGeometry().Size.X - 35;
	}
	else if (TableWidth != 0)
	{
		TableWidth -= 35;
	}
	
	UpdataMinMaxValue();
	//如果过所需要的宽度超过当前表所展示的空间则需要创建滚动条
	if (MinWidth > 0 && TableWidth > 0 && MinWidth > TableWidth)
	{
		ShowZheLine = false;
		ScrollUpdataCustomList(MinWidth / ListData.Num());
	}
	else
	{
		UpdataCustomList();
	}
}

void SCustomList::UpdataMinMaxValue()
{
	float _minValue,_maxValue;
	bool first = false;
	if(PillarNum >= 1)
	{
		for (auto &item : ListData)
		{
			if(!first)
			{
				_minValue = _maxValue = item.Value.OneValue;
				first = true;
			}
			else
			{
				if(item.Value.OneValue > _maxValue)
				{
					_maxValue = item.Value.OneValue;
				}
				if(item.Value.OneValue < _minValue)
				{
					_minValue = item.Value.OneValue;
				}
			}
		}
	}
	if(PillarNum >= 2)
	{
		for (auto &item : ListData)
		{
			if(item.Value.TwoValue > _maxValue)
			{
				_maxValue = item.Value.TwoValue;
			}
			if(item.Value.TwoValue < _minValue)
			{
				_minValue = item.Value.TwoValue;
			}
		}
	}
	if(PillarNum >= 3)
	{
		for (auto &item : ListData)
		{
			if(item.Value.ThreeValue > _maxValue)
			{
				_maxValue = item.Value.ThreeValue;
			}
			if(item.Value.ThreeValue < _minValue)
			{
				_minValue = item.Value.ThreeValue;
			}
		}
	}
	if(PillarNum >= 4)
	{
		for (auto &item : ListData)
		{
			if(item.Value.FourValue > _maxValue)
			{
				_maxValue = item.Value.FourValue;
			}
			if(item.Value.FourValue < _minValue)
			{
				_minValue = item.Value.FourValue;
			}
		}
	}


	if(_maxValue == _minValue)
		_minValue = 0;
	float interval = FMath::Abs(_maxValue - _minValue);
	if(interval == 0 || first == false)
		return;
	if(MaxValue > MinValue && (_maxValue >MaxValue || _minValue < MinValue))
	{
		MaxValue = _maxValue;
		MinValue = _minValue;
		GrowValue = (MaxValue - MinValue) / 5;
	}
	if(MinValue > MaxValue && (_maxValue < MaxValue || _minValue > MinValue))
	{
		MaxValue = _minValue;
		MinValue = _maxValue;
		GrowValue = (MaxValue - MinValue) / 5;
	}
}

int SCustomList::FloatAccuracy(int &MaxLen)
{
	TArray<FString> NumList;
	//精确度
	int AccuracyNum = 0;
	//先转成字符串
	for (float item = MaxValue;;MaxValue > MinValue?  item -= GrowValue :  item += GrowValue)
	{
		if (MaxValue > MinValue)
		{
			if (item <= MinValue)
				break;
		}
		else
		{
			if (item >= MinValue)
				break;
		}
		
		NumList.Add(FString::Printf(TEXT("%f"), item));
	}

	for(int i = 0; i< NumList.Num();i++)
	{
		int32 WildCardIndex = INDEX_NONE;
		//找到这个"."
		if (NumList[i].FindChar(TEXT('.'), WildCardIndex))
		{
			//获取小数点后面的数值
			FString DianRight = NumList[i].Right(NumList[i].Len() - (WildCardIndex + 1));
			int FindItem = DianRight.Find(TEXT("00"));
			if(FindItem == INDEX_NONE)
			{
				FindItem = DianRight.Find(TEXT("99"));
			}
			if(FindItem != INDEX_NONE)
			{
				if(FindItem > AccuracyNum)
				AccuracyNum = FindItem;
			}
		}
	}

	if(AccuracyNum != 0)
	{
		for(int i = 0; i < NumList.Num();i++)
		{
			int32 WildCardIndex = INDEX_NONE;
			//找到这个"."
			if (NumList[i].FindChar(TEXT('.'), WildCardIndex))
			{
				if(WildCardIndex + 1 + AccuracyNum > MaxLen)
					MaxLen = WildCardIndex + 1 + AccuracyNum;
			}
		}
	}
	else
	{
		MaxLen = FMath::Max(FString::SanitizeFloat(MaxValue).Len(),
							FString::SanitizeFloat(MinValue).Len()); //最大字符长度
	}
	return AccuracyNum;
}
//保留精确度多余的部分进行剔除
FString SCustomList::GetFloatAccuracy(float Value, int Accuracy)
{
	FString Ref = FString::SanitizeFloat(Value);
	if (Ref.Len() > 2 && !Ref.Right(2).Compare(".0"))
	{
		Ref = Ref.Left(Ref.Len() - 2);
	}
	int32 WildCardIndex = INDEX_NONE;
	//找到这个"."
	if (Ref.FindChar(TEXT('.'), WildCardIndex))
	{
		
		int StrLen = WildCardIndex + 1 + Accuracy;
		if(StrLen < Ref.Len())
		{
			FString RightStr = Ref.Right(Ref.Len() - StrLen);
			Ref = Ref.Left(StrLen);
			//判断被截断的是否是99,如果是则Ref位数+1
			if(RightStr.Len() >= 2 && !RightStr.Left(2).Compare("99"))
			{
					TCHAR *ch = GetData(Ref);
				for(int i = Ref.Len() - 1;i >= 0;i--)
				{
					if(ch[i] == '.')
						continue;
					if(ch[i] != '9')
					{
						ch[i] += 1;
						break;
					}
					else
					{
						ch[i] = '0';
					}
				}
			}
		}
	}
	return Ref;
}

void SCustomList::UpdataCustomList()
{
	YuanImageS.Empty();
	int MaxLen = 0;
	//获取小数点后面的精确度
	int AccuracyNum = FloatAccuracy(MaxLen);

	//这里的代码主要是绘制左侧的数字和后面的横线
	TSharedPtr<SVerticalBox> DrawLine = SNew(SVerticalBox);

	for (float item = MaxValue;;MaxValue > MinValue?  item -= GrowValue :  item += GrowValue)
	{
		if (MaxValue > MinValue)
		{
			if (item <= MinValue)
				break;
		}
		else
		{
			if (item >= MinValue)
				break;
		}
		if (FMath::Abs(item - MinValue )< 0.00001)
			continue;
		FString ValueStr = GetFloatAccuracy(item,AccuracyNum);
		if (ValueStr.Len() > 1 && !ValueStr.Right(1).Compare("."))
		{
			ValueStr = ValueStr.Left(ValueStr.Len() - 1);
		}
		if (ValueStr.Len() < MaxLen)
		{
			int AddSpace = MaxLen - ValueStr.Len();
			FString Space = "";
			for (int i = 0; i < AddSpace; i++)
			{
				Space.Append("  ");
			}
			ValueStr = Space + ValueStr;
		}
		DrawLine->AddSlot().FillHeight(1)
		[
			SNew(SHorizontalBox)
			+ SHorizontalBox::Slot().AutoWidth().Padding(FMargin(0, -10, 0, 0))
			[
				SNew(STextBlock_TextStyleLambda_List)
             			.Justification(ETextJustify::Right)
             			.Text(FText::FromString(ValueStr))
             			.TEXTSTYLE("AlibabaRegular_12_83AAD6FF")
			]
			+ SHorizontalBox::Slot()
			  .Padding(FMargin(12, 0, 0, 0))
			  .FillWidth(1)
			[
				SNew(SVerticalBox)
				+ SVerticalBox::Slot().AutoHeight()
				[
					SNew(SBox).HeightOverride(1)
					[
						SNew(SImage).SETIMAGE("XuXian")
					]
				]
				+ SVerticalBox::Slot().FillHeight(1)
				[
					SNew(SSpacer)
				]
			]
		];
	}

	FString TempStr = "";
	FString MinValueStr = GetFloatAccuracy(MinValue,AccuracyNum);
	if (MinValueStr.Len() > 1 && !MinValueStr.Right(1).Compare("."))
	{
		MinValueStr = MinValueStr.Left(MinValueStr.Len() - 1);
	}
	int MinValueLen = MinValueStr.Len();
	for (int i = 0; i < MaxLen - MinValueLen; i++)
		TempStr.Append("  ");
	MinValueStr = TempStr + MinValueStr;


	TMap<FString, FCustomListInfo> TempListData = ListData;
	Intervalmapping();

	//用于显示图表中背景的线和柱子
	TSharedPtr<SOverlay> List_SOverlay = SNew(SOverlay);
	//用于显示柱子
	TSharedPtr<SHorizontalBox> Pillar = SNew(SHorizontalBox);
	//用于显示柱子对应的名字
	TSharedPtr<SHorizontalBox> NameLise = SNew(SHorizontalBox);


	for (auto& item : ListData)
	{
		NameLise->AddSlot().FillWidth(1)
		[

			SNew(SMultiLineEditableText)
			.Justification(ETextJustify::Center)
				.TextStyle(ListUIStyle::GetTextBlockStyle("AlibabaRegular_10_83AAD6FF"))
				 .IsReadOnly(true) //只读属性
				 .AutoWrapText(true)
				 .ToolTipText(FText::FromString(item.Key))
				 .Text(FText::FromString(item.Key))
		];

		int Average = 0;
		TSharedPtr<SHorizontalBox> TempHorizontalBox = SNew(SHorizontalBox);
		TempHorizontalBox->AddSlot().FillWidth(1)[SNew(SSpacer)]; //最左边的空隙
		if (PillarNum >= 1)
		{
			int OldValue = TempListData[item.Key].OneValue;
			Average += item.Value.OneValue;
			FString ImageName = "ZhuZi_Blue";
			if (ShowWarningLine && (item.Value.OneValue >= WarningValue && MaxValue > MinValue || item.Value.OneValue <=WarningValue && MaxValue < MinValue ))
			{
				ImageName = "ZhuZi_Warning";
			}
			TempHorizontalBox->AddSlot().FillWidth(1)
			[
				SNew(SVerticalBox)
				+ SVerticalBox::Slot().FillHeight(MaxValue - item.Value.OneValue)
				[
					SNew(SSpacer)
				]
				+ SVerticalBox::Slot().FillHeight(item.Value.OneValue)
				[
					SNew(SImage)
						.SETIMAGE(ImageName)
						.ToolTipText(FText::FromString(FString::SanitizeFloat(OldValue)))
				]
			];
		}
		if (PillarNum >= 2)
		{
			int OldValue = TempListData[item.Key].TwoValue;
			Average += item.Value.TwoValue;
			FString ImageName = "ZhuZi_Green";
			if (ShowWarningLine && item.Value.TwoValue >= WarningValue)
			{
				ImageName = "ZhuZi_Warning";
			}
			TempHorizontalBox->AddSlot().FillWidth(0.5)[SNew(SSpacer)];
			TempHorizontalBox->AddSlot().FillWidth(1)
			[
				SNew(SVerticalBox)
				+ SVerticalBox::Slot().FillHeight(MaxValue - item.Value.TwoValue)
				[
					SNew(SSpacer)
				]
				+ SVerticalBox::Slot().FillHeight(item.Value.TwoValue)
				[
					SNew(SImage)
						.SETIMAGE(ImageName)
						.ToolTipText(FText::FromString(FString::SanitizeFloat(OldValue)))
				]
			];
		}
		if (PillarNum >= 3)
		{
			int OldValue = TempListData[item.Key].ThreeValue;
			Average += item.Value.ThreeValue;
			FString ImageName = "ZhuZi_Yellow";
			if (ShowWarningLine && item.Value.ThreeValue >= WarningValue)
			{
				ImageName = "ZhuZi_Warning";
			}
			TempHorizontalBox->AddSlot().FillWidth(0.5)[SNew(SSpacer)];
			TempHorizontalBox->AddSlot().FillWidth(1)
			[
				SNew(SVerticalBox)
				+ SVerticalBox::Slot().FillHeight(MaxValue - item.Value.ThreeValue)
				[
					SNew(SSpacer)
				]
				+ SVerticalBox::Slot().FillHeight(item.Value.ThreeValue)
				[
					SNew(SImage)
						.SETIMAGE(ImageName)
						.ToolTipText(FText::FromString(FString::SanitizeFloat(OldValue)))
				]
			];
		}
		if (PillarNum >= 4)
		{
			int FourValue = TempListData[item.Key].FourValue;
			Average += item.Value.FourValue;
			FString ImageName = "ZhuZi_White";
			if (ShowWarningLine && item.Value.FourValue >= WarningValue)
			{
				ImageName = "ZhuZi_Warning";
			}
			TempHorizontalBox->AddSlot().FillWidth(0.5)[SNew(SSpacer)];
			TempHorizontalBox->AddSlot().FillWidth(1)
			[
				SNew(SVerticalBox)
				+ SVerticalBox::Slot().FillHeight(MaxValue - item.Value.FourValue)
				[
					SNew(SSpacer)
				]
				+ SVerticalBox::Slot().FillHeight(item.Value.FourValue)
				[
					SNew(SImage)
						.SETIMAGE("ZhuZi_White")
						.ToolTipText(FText::FromString(FString::SanitizeFloat(FourValue)))
				]
			];
		}
		TempHorizontalBox->AddSlot().FillWidth(1)[SNew(SSpacer)]; //最右边的空隙
		Average /= PillarNum;

		TSharedPtr<SImage> TempYuan;
		Pillar->AddSlot().FillWidth(1).Padding(FMargin(7, 0, 0, 0))
		[

			SNew(SOverlay)
			+ SOverlay::Slot()
			[
				SNew(SColorBlock)
			.Visibility_Lambda([this]()
				                 {
					                 if (PillarBg)
						                 return EVisibility::Visible;
					                 else
					                 {
						                 return EVisibility::Collapsed;
					                 }
				                 })
				.Color(FLinearColor(0.27, 0.4, 0.7, 0.1))
			]
			+ SOverlay::Slot()
			[
				TempHorizontalBox.ToSharedRef()
			]
			+ SOverlay::Slot()
			[
				SNew(SVerticalBox)
				+ SVerticalBox::Slot().FillHeight(MaxValue - Average)
				[
					SNew(SSpacer)
				]
				+ SVerticalBox::Slot()
				  .FillHeight(Average)
				  .VAlign(VAlign_Top)
				  .Padding(FMargin(0, -12, 0, 0))
				  .HAlign(HAlign_Center)
				[
					SAssignNew(TempYuan, SImage)
					.SETIMAGE("Yuan")
					.ColorAndOpacity_Lambda([this]()
					{
						if (ShowYuan)
							return FLinearColor(1, 1, 1, 1);
						else //让这个图片接近于透明
							return FLinearColor(0, 0, 0, 0.001);
					})
				]
			]

		];

		YuanImageS.Add(TempYuan);
	}


	List_SOverlay->AddSlot()
	[
		DrawLine.ToSharedRef()
	];
	List_SOverlay->AddSlot()[
		SNew(SHorizontalBox)
		+ SHorizontalBox::Slot().AutoWidth()
		[
			SNew(STextBlock_TextStyleLambda_List)
				 .Justification(ETextJustify::Right)
				 .Text(FText::FromString(TempStr))
				 .TEXTSTYLE("AlibabaRegular_12_83AAD6FF")
		]
		+ SHorizontalBox::Slot().FillWidth(1).Padding(FMargin(12 * MinValueLen, 0, 0, 0))
		[
			Pillar.ToSharedRef()
		]
	];

	//显示整个表格
	TSharedPtr<SVerticalBox> ShowList;
	SAssignNew(ShowList, SVerticalBox)
		+ SVerticalBox::Slot().FillHeight(1)
		[
			List_SOverlay.ToSharedRef()
		]
		+ SVerticalBox::Slot().AutoHeight()
		[
			SNew(SBox).HeightOverride(1)
			[
				SNew(SHorizontalBox)
				+ SHorizontalBox::Slot().AutoWidth()
				[
					SNew(STextBlock_TextStyleLambda_List)
					 .Justification(ETextJustify::Right)
					 .Text(FText::FromString(TempStr))
					 .TEXTSTYLE("AlibabaRegular_12_83AAD6FF")
				]
				+ SHorizontalBox::Slot().FillWidth(1).Padding(FMargin(12 * MinValueLen, 0, 0, 0))
				[
					SNew(SColorBlock).Color(FLinearColor(0.27, 0.4, 0.67, 1.0))
				]
			]
		]
		+ SVerticalBox::Slot().AutoHeight()
		[
			SNew(SHorizontalBox)
			+ SHorizontalBox::Slot().AutoWidth().Padding(FMargin(0, -10, 0, 0))
			[
				SNew(STextBlock_TextStyleLambda_List)
						 .Justification(ETextJustify::Right)
						 .Text(FText::FromString(MinValueStr))
						 .TEXTSTYLE("AlibabaRegular_12_83AAD6FF")
			]
			+ SHorizontalBox::Slot().FillWidth(1).Padding(FMargin(12, 0, 0, 0))
			[
				NameLise.ToSharedRef()
			]
		];

	TSharedPtr<SOverlay> tempOverlay = SNew(SOverlay);
	tempOverlay->AddSlot()[
		SNew(SVerticalBox)
		.Visibility_Lambda([this]()
		{
			if (ShowWarningLine)
				return EVisibility::Visible;
			else
			{
				return EVisibility::Collapsed;
			}
		})
		+ SVerticalBox::Slot().FillHeight(MaxValue - WarningValue)
		[
			SNew(SSpacer)
		]
		+ SVerticalBox::Slot().FillHeight(WarningValue)
		[
			SNew(SVerticalBox)
			+ SVerticalBox::Slot().AutoHeight().Padding(FMargin(20, -3, 0, 0))
			[
				SNew(SImage).SETIMAGE("WarningLine")
			]
			+ SVerticalBox::Slot().FillHeight(1)
			[
				SNew(SSpacer)
			]
		]
	];
	tempOverlay->AddSlot()[ShowList.ToSharedRef()];
	ListContent->SetContent(tempOverlay.ToSharedRef());
}

void SCustomList::Intervalmapping()
{
	for (auto& item : ListData)
	{
		item.Value.OneValue = UKismetMathLibrary::MapRangeUnclamped(item.Value.OneValue, MinValue, MaxValue, 0, 100);
		item.Value.TwoValue = UKismetMathLibrary::MapRangeUnclamped(item.Value.TwoValue, MinValue, MaxValue, 0, 100);
		item.Value.ThreeValue = UKismetMathLibrary::MapRangeUnclamped(item.Value.ThreeValue, MinValue, MaxValue, 0, 100);
		item.Value.FourValue = UKismetMathLibrary::MapRangeUnclamped(item.Value.FourValue, MinValue, MaxValue, 0, 100);
	}
	WarningValue = UKismetMathLibrary::MapRangeUnclamped(WarningValue, MinValue, MaxValue, 0, 100);
	MinValue = UKismetMathLibrary::MapRangeUnclamped(MinValue, MinValue, MaxValue, 0, 100);
	MaxValue = UKismetMathLibrary::MapRangeUnclamped(MaxValue, MinValue, MaxValue, 0, 100);
}

void SCustomList::ScrollUpdataCustomList(int width)
{
	YuanImageS.Empty();
	int MaxLen = 0;
	//获取小数点后面的精确度
	int AccuracyNum = FloatAccuracy(MaxLen);
	//这里的代码主要是绘制左侧的数字和后面的横线
	TSharedPtr<SVerticalBox> DrawLine = SNew(SVerticalBox);
	for (int item = MaxValue; item >= GrowValue; item -= GrowValue)
	{
					FString ValueStr = GetFloatAccuracy(item,AccuracyNum);
		if (ValueStr.Len() > 1 && !ValueStr.Right(1).Compare("."))
		{
			ValueStr = ValueStr.Left(ValueStr.Len() - 1);
		}

		if (ValueStr.Len() < MaxLen)
		{
			int AddSpace = MaxLen - ValueStr.Len();
			FString Space = "";
			for (int i = 0; i < AddSpace; i++)
			{
				Space.Append("  ");
			}
			ValueStr = Space + ValueStr;
		}
		DrawLine->AddSlot().FillHeight(1)
		[
			SNew(SHorizontalBox)
			+ SHorizontalBox::Slot().AutoWidth().Padding(FMargin(0, -10, 0, 0))
			[
				SNew(STextBlock_TextStyleLambda_List)
             			.Justification(ETextJustify::Right)
             			.Text(FText::FromString(ValueStr))
             			.TEXTSTYLE("AlibabaRegular_12_83AAD6FF")
			]
			+ SHorizontalBox::Slot()
			  .Padding(FMargin(12, 0, 0, 0))
			  .FillWidth(1)
			[
				SNew(SVerticalBox)
				+ SVerticalBox::Slot().AutoHeight()
				[
					SNew(SBox).HeightOverride(1)
					[
						SNew(SImage).SETIMAGE("XuXian")
					]
				]
				+ SVerticalBox::Slot().FillHeight(1)
				[
					SNew(SSpacer)
				]
			]
		];
	}


	//用于显示图表中背景的线和柱子
	TSharedPtr<SOverlay> List_SOverlay = SNew(SOverlay);
	//用于显示柱子
	TSharedPtr<SHorizontalBox> Pillar = SNew(SHorizontalBox);
	//用于显示柱子对应的名字
	TSharedPtr<SHorizontalBox> NameLise = SNew(SHorizontalBox);


	for (auto& item : ListData)
	{
		NameLise->AddSlot().AutoWidth().Padding(FMargin(7, 10, 0, 0))
		[
			SNew(SBox).WidthOverride(width)
			[
				SNew(SMultiLineEditableText)
				.Justification(ETextJustify::Center)
				.TextStyle(ListUIStyle::GetTextBlockStyle("AlibabaRegular_10_83AAD6FF"))
				.IsReadOnly(true) //只读属性
				.AutoWrapText(true)
				.ToolTipText(FText::FromString(item.Key))
				.Text(FText::FromString(item.Key))
			]
		];

		int Average = 0;
		TSharedPtr<SHorizontalBox> TempHorizontalBox = SNew(SHorizontalBox);
		TempHorizontalBox->AddSlot().FillWidth(1)[SNew(SSpacer)]; //最左边的空隙
		if (PillarNum >= 1)
		{
			Average += item.Value.OneValue;
			FString ImageName = "ZhuZi_Blue";
			if (ShowWarningLine && item.Value.OneValue >= WarningValue)
			{
				ImageName = "ZhuZi_Warning";
			}
			TempHorizontalBox->AddSlot().FillWidth(1)
			[
				SNew(SVerticalBox)
				+ SVerticalBox::Slot().FillHeight(MaxValue - item.Value.OneValue)
				[
					SNew(SSpacer)
				]
				+ SVerticalBox::Slot().FillHeight(item.Value.OneValue)
				[
					SNew(SImage)
						.SETIMAGE(ImageName)
						.ToolTipText(FText::FromString(FString::SanitizeFloat(item.Value.OneValue)))
				]
			];
		}
		if (PillarNum >= 2)
		{
			Average += item.Value.TwoValue;
			FString ImageName = "ZhuZi_Green";
			if (ShowWarningLine && item.Value.TwoValue >= WarningValue)
			{
				ImageName = "ZhuZi_Warning";
			}
			TempHorizontalBox->AddSlot().FillWidth(0.5)[SNew(SSpacer)];
			TempHorizontalBox->AddSlot().FillWidth(1)
			[
				SNew(SVerticalBox)
				+ SVerticalBox::Slot().FillHeight(MaxValue - item.Value.TwoValue)
				[
					SNew(SSpacer)
				]
				+ SVerticalBox::Slot().FillHeight(item.Value.TwoValue)
				[
					SNew(SImage)
						.SETIMAGE(ImageName)
						.ToolTipText(FText::FromString(FString::SanitizeFloat(item.Value.TwoValue)))
				]
			];
		}
		if (PillarNum >= 3)
		{
			Average += item.Value.ThreeValue;
			FString ImageName = "ZhuZi_Yellow";
			if (ShowWarningLine && item.Value.ThreeValue >= WarningValue)
			{
				ImageName = "ZhuZi_Warning";
			}
			TempHorizontalBox->AddSlot().FillWidth(0.5)[SNew(SSpacer)];
			TempHorizontalBox->AddSlot().FillWidth(1)
			[
				SNew(SVerticalBox)
				+ SVerticalBox::Slot().FillHeight(MaxValue - item.Value.ThreeValue)
				[
					SNew(SSpacer)
				]
				+ SVerticalBox::Slot().FillHeight(item.Value.ThreeValue)
				[
					SNew(SImage)
						.SETIMAGE(ImageName)
						.ToolTipText(FText::FromString(FString::SanitizeFloat(item.Value.ThreeValue)))
				]
			];
		}
		if (PillarNum >= 4)
		{
			Average += item.Value.FourValue;
			FString ImageName = "ZhuZi_White";
			if (ShowWarningLine && item.Value.FourValue >= WarningValue)
			{
				ImageName = "ZhuZi_Warning";
			}
			TempHorizontalBox->AddSlot().FillWidth(0.5)[SNew(SSpacer)];
			TempHorizontalBox->AddSlot().FillWidth(1)
			[
				SNew(SVerticalBox)
				+ SVerticalBox::Slot().FillHeight(MaxValue - item.Value.FourValue)
				[
					SNew(SSpacer)
				]
				+ SVerticalBox::Slot().FillHeight(item.Value.FourValue)
				[
					SNew(SImage)
						.SETIMAGE("ZhuZi_White")
						.ToolTipText(FText::FromString(FString::SanitizeFloat(item.Value.FourValue)))
				]
			];
		}
		TempHorizontalBox->AddSlot().FillWidth(1)[SNew(SSpacer)]; //最右边的空隙
		Average /= PillarNum;

		TSharedPtr<SImage> TempYuan;
		Pillar->AddSlot().FillWidth(1).Padding(FMargin(7, 0, 0, 0))
		[

			SNew(SBox).WidthOverride(width)
			[
				SNew(SOverlay)
				+ SOverlay::Slot()
				[
					SNew(SColorBlock) //显示柱状图的背景颜色
			.Visibility_Lambda([this]()
					                 {
						                 if (PillarBg)
							                 return EVisibility::Visible;
						                 else
						                 {
							                 return EVisibility::Collapsed;
						                 }
					                 })
				.Color(FLinearColor(0.27, 0.4, 0.7, 0.1))
				]
				+ SOverlay::Slot() //柱状图
				[
					TempHorizontalBox.ToSharedRef()
				]
				+ SOverlay::Slot() //柱状图顶上的圆
				[
					SNew(SVerticalBox)
					+ SVerticalBox::Slot().FillHeight(MaxValue - Average)
					[
						SNew(SSpacer)
					]
					+ SVerticalBox::Slot()
					  .FillHeight(Average)
					  .VAlign(VAlign_Top)
					  .Padding(FMargin(0, -12, 0, 0))
					  .HAlign(HAlign_Center)
					[
						SAssignNew(TempYuan, SImage)
						.SETIMAGE("Yuan")
						.ColorAndOpacity_Lambda([this]()
						{
							if (ShowYuan)
								return FLinearColor(1, 1, 1, 1);
							else //让这个图片接近于透明
								return FLinearColor(0, 0, 0, 0.001);
						})
					]
				]

			]
		];

		YuanImageS.Add(TempYuan);
	}

	FString TempStr = "";
	FString ZeroStr = "";
	for (int i = 0; i < MaxLen; i++)
		TempStr.Append("  ");
	ZeroStr = TempStr.Left(TempStr.Len() - 2);
	ZeroStr.Append("0");
	List_SOverlay->AddSlot()
	[
		DrawLine.ToSharedRef()
	];
	List_SOverlay->AddSlot()[
		SNew(SHorizontalBox)
		+ SHorizontalBox::Slot().AutoWidth()
		[
			SNew(STextBlock_TextStyleLambda_List)
				 .Justification(ETextJustify::Right)
				 .Text(FText::FromString(TempStr))
				 .TEXTSTYLE("AlibabaRegular_12_83AAD6FF")
		]
		+ SHorizontalBox::Slot().FillWidth(1).Padding(FMargin(12, 0, 0, 0))
		[
			SAssignNew(ZhuScroll, Plugin_List::SCollisionScrollBox_List)
			.Orientation(EOrientation::Orient_Horizontal)
			.ScrollBarVisibility(EVisibility::Collapsed)
			.OnUserScrolled_Lambda([this](float jindu)
			{
				float moveto = jindu / ZhuScroll->GetScrollOffsetOfEnd();
				Slider->SetValue(moveto);
				TextScroll->SetScrollOffset(jindu);
			})
			+ Plugin_List::SCollisionScrollBox_List::Slot()
			[
				Pillar.ToSharedRef()
			]
		]
	];

	//显示整个表格
	TSharedPtr<SVerticalBox> ShowList;
	SAssignNew(ShowList, SVerticalBox)
		+ SVerticalBox::Slot().FillHeight(1)
		[
			List_SOverlay.ToSharedRef()
		]
		+ SVerticalBox::Slot().AutoHeight()
		[
			SNew(SBox).HeightOverride(1)
			[
				SNew(SHorizontalBox)
				+ SHorizontalBox::Slot().AutoWidth()
				[
					SNew(STextBlock_TextStyleLambda_List)
					 .Justification(ETextJustify::Right)
					 .Text(FText::FromString(TempStr))
					 .TEXTSTYLE("AlibabaRegular_12_83AAD6FF")
				]
				+ SHorizontalBox::Slot().FillWidth(1).Padding(FMargin(12, 0, 0, 0))
				[
					SNew(SVerticalBox)
					+ SVerticalBox::Slot().AutoHeight()
					[
						SNew(SBox).HeightOverride(1)
						[
							SNew(SColorBlock).Color(FLinearColor(0.27, 0.4, 0.67, 1.0))
						]
					]
					+ SVerticalBox::Slot().AutoHeight()
					[
						SAssignNew(Slider, SSlider)
				.Style(ListUIStyle::SliderStyle)
				.IndentHandle(false)
					.OnValueChanged_Lambda([this](float value)
						                           {
							                           float moveto = value * TextScroll->GetScrollOffsetOfEnd();
							                           TextScroll->SetScrollOffset(moveto);
							                           ZhuScroll->SetScrollOffset(moveto);
						                           })
					.SliderBarColor(FLinearColor(1, 1, 1, 0))
					.Orientation(Orient_Horizontal)
					.MaxValue(1)
					.MinValue(0)
					.Value(0.0f)
					]
				]
			]
		]
		+ SVerticalBox::Slot().AutoHeight()
		[
			SNew(SHorizontalBox)
			+ SHorizontalBox::Slot().AutoWidth().Padding(FMargin(0, -10, 0, 0))
			[
				SNew(STextBlock_TextStyleLambda_List)
						 .Justification(ETextJustify::Right)
						 .Text(FText::FromString(ZeroStr))
						 .TEXTSTYLE("AlibabaRegular_12_83AAD6FF")
			]
			+ SHorizontalBox::Slot().FillWidth(1).Padding(FMargin(12, 0, 0, 0))
			[
				SAssignNew(TextScroll, Plugin_List::SCollisionScrollBox_List)
				.Orientation(EOrientation::Orient_Horizontal)
				.ScrollBarVisibility(EVisibility::Collapsed)
				.OnUserScrolled_Lambda([this](float jindu)
				{
					float moveto = jindu / ZhuScroll->GetScrollOffsetOfEnd();
					Slider->SetValue(moveto);
					ZhuScroll->SetScrollOffset(jindu);
				})
				+ Plugin_List::SCollisionScrollBox_List::Slot()
				[
					NameLise.ToSharedRef()
				]
			]
		];

	TSharedPtr<SOverlay> tempOverlay = SNew(SOverlay);
	tempOverlay->AddSlot()[
		SNew(SVerticalBox)
		.Visibility_Lambda([this]()
		{
			if (ShowWarningLine)
				return EVisibility::Visible;
			else
			{
				return EVisibility::Collapsed;
			}
		})
		+ SVerticalBox::Slot().FillHeight(MaxValue - WarningValue)
		[
			SNew(SSpacer)
		]
		+ SVerticalBox::Slot().FillHeight(WarningValue)
		[
			SNew(SVerticalBox)
			+ SVerticalBox::Slot().AutoHeight().Padding(FMargin(20, -3, 0, 0))
			[
				SNew(SImage).SETIMAGE("WarningLine")
			]
			+ SVerticalBox::Slot().FillHeight(1)
			[
				SNew(SSpacer)
			]
		]
	];
	tempOverlay->AddSlot()[ShowList.ToSharedRef()];
	ListContent->SetContent(tempOverlay.ToSharedRef());
}


void SCustomList::UpDataTitleName(const FString InTitleName)
{
	TitleText->SetText(FText::FromString(InTitleName));
}

void SCustomList::UpDataOneInfoName(const FString InOneInfoName)
{
	OneInfo->SetText(FText::FromString(InOneInfoName));
}

void SCustomList::UpDataTwoInfoName(const FString InFourInfoName)
{
	TwoInfo->SetText(FText::FromString(InFourInfoName));
}

void SCustomList::UpDataThreeInfoName(const FString InThreeInfoName)
{
	ThreeInfo->SetText(FText::FromString(InThreeInfoName));
}

void SCustomList::UpDataFourInfoName(const FString InFourInfoName)
{
	FourInfo->SetText(FText::FromString(InFourInfoName));
}

void SCustomList::CleanList()
{
	UpDataList(TMap<FString, FCustomListInfo>());
}

FReply SCustomList::OnMouseWheel(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent)
{
	SCompoundWidget::OnMouseWheel(MyGeometry, MouseEvent);
	return FReply::Handled();
}

FReply SCustomList::OnMouseButtonDoubleClick(const FGeometry& InMyGeometry, const FPointerEvent& InMouseEvent)
{
	SCompoundWidget::OnMouseButtonDoubleClick(InMyGeometry, InMouseEvent);
	return FReply::Handled();
}

FReply SCustomList::OnMouseMove(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent)
{
	SCompoundWidget::OnMouseMove(MyGeometry, MouseEvent);
	return FReply::Handled();
}

FReply SCustomList::OnMouseButtonDown(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent)
{
	SCompoundWidget::OnMouseButtonDown(MyGeometry, MouseEvent);
	return FReply::Handled();
}